package com.group.patients.service.impl;

import com.group.commons.entity.patient.PatientFamily;
import com.group.patients.dao.PatientFamilyDao;
import com.group.service.PatientFamilyService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * (PatientFamily)表服务实现类
 *
 * @author makejava
 * @since 2022-06-07 11:12:28
 */
@Service("patientFamilyService")
public class PatientFamilyServiceImpl implements PatientFamilyService {
    @Resource
    private PatientFamilyDao patientFamilyDao;

    /**
     * 通过ID查询单条数据
     *
     * @param patientid 主键
     * @return 实例对象
     */
    @Override
    public PatientFamily queryById(Integer patientid) {
        return this.patientFamilyDao.queryById(patientid);
    }

    /**
     * 分页查询
     *
     * @param patientFamily 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<PatientFamily> queryByPage(PatientFamily patientFamily, PageRequest pageRequest) {
        long total = this.patientFamilyDao.count(patientFamily);
        return new PageImpl<>(this.patientFamilyDao.queryAllByLimit(patientFamily, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param patientFamily 实例对象
     * @return 实例对象
     */
    @Override
    public PatientFamily insert(PatientFamily patientFamily) {
        this.patientFamilyDao.insert(patientFamily);
        return patientFamily;
    }

    /**
     * 修改数据
     *
     * @param patientFamily 实例对象
     * @return 实例对象
     */
    @Override
    public PatientFamily update(PatientFamily patientFamily) {
        this.patientFamilyDao.update(patientFamily);
        return this.queryById(patientFamily.getPatientid());
    }

    /**
     * 通过主键删除数据
     *
     * @param patientid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer patientid) {
        return this.patientFamilyDao.deleteById(patientid) > 0;
    }
}
